package com.smart.controller;

import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.common.PageInfo;
import com.smart.common.scheduler.service.TempTaskScheduleService;
import com.smart.common.scheduler.service.WeeklyTaskScheduleService;
import com.smart.model.request.ProjectReportRequest;
import com.smart.model.vo.ProjectItemVO;
import com.smart.model.vo.ProjectWeeklyItemVO;
import com.smart.service.ProjectReportService;
import com.smart.model.vo.ProjectReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/report")
@Api(tags = {"云服务平台#数据提报模块"})
public class ProjectReportController {

    @Autowired
    private ProjectReportService projectReportService;
    @Autowired
    private TempTaskScheduleService tempTaskScheduleService;
    @Autowired
    private WeeklyTaskScheduleService weeklyTaskScheduleService;

    @WebAccess(login = true)
    @ApiOperation("【临时提报】分页查询")
    @PostMapping("/temp/pageQuery")
    public WebResponse<PageInfo<ProjectReportVO>> tempPageQuery(@RequestBody ProjectReportRequest request) {
        return WebResponse.build(projectReportService.tempPageQuery(request));
    }
    @WebAccess(login = true)
    @ApiOperation(value = "【临时提报|周报】查看", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<ProjectReportVO> getByKey(@PathVariable("id") long id) {
        return WebResponse.build(projectReportService.getByKey(id));
    }
    @WebAccess(login = true)
    @ApiOperation("【临时提报|周报】提报||编辑")
    @PostMapping("/update")
    public WebResponse<Boolean> updateByKey(@Valid @RequestBody ProjectReportRequest request) {
        return WebResponse.build(projectReportService.updateByKey(request));
    }
    @WebAccess(login = true)
    @ApiOperation("【临时提报】查询提报内容填报项目")
    @ApiImplicitParam(name = "id", value = "数据id")
    @PostMapping("/queryReportItem/{id}")
    public WebResponse<List<ProjectItemVO>> queryReportItem(@PathVariable("id") Long id) {
        return WebResponse.build(projectReportService.queryReportItem(id));
    }

    @WebAccess(login = true)
    @ApiOperation("【周报提报】查询提报内容填报项目")
    @ApiImplicitParam(name = "id", value = "数据id")
    @PostMapping("/queryWeeklyReportItem/{id}")
    public WebResponse<List<ProjectWeeklyItemVO>> queryWeeklyReportItem(@PathVariable("id") Long id) {
        return WebResponse.build(projectReportService.queryWeeklyReportItem(id));
    }

    @WebAccess(login = true)
    @ApiOperation("【周报】分页查询")
    @PostMapping("/weekly/pageQuery")
    public WebResponse<PageInfo<ProjectReportVO>> weeklyPageQuery(@RequestBody ProjectReportRequest request) {
        return WebResponse.build(projectReportService.weeklyPageQuery(request));
    }

    @ApiOperation("手动生成临时提报任务下发到项目---快速生成任务，前端无需对接该接口：工具接口")
    @PostMapping("/handleSend/tempTask/{taskId}")
    public WebResponse<Boolean> handleSendTempTask(@PathVariable("taskId") long taskId) {
        return WebResponse.build(tempTaskScheduleService.sendTemplateTask(taskId));
    }

    @ApiOperation("手动生成周报任务下发到项目---快速生成任务，前端无需对接该接口：工具接口")
    @PostMapping("/handleSend/weeklyTask")
    public WebResponse<Boolean> handleSendWeeklyTask() {
        weeklyTaskScheduleService.createWeeklyTask();
        return WebResponse.build(true);
    }

    @ApiOperation("手动生成周报任务下发到项目---快速生成任务，前端无需对接该接口：工具接口")
    @PostMapping("/handleSend/resendWeeklyTask")
    public WebResponse<Boolean> resendWeeklyTask() {
        weeklyTaskScheduleService.resendWeeklyTask();
        return WebResponse.build(true);
    }
}
